27. Exercise: Selection and SelectionArgs

Selection and SelectionArgs

So, now that you’ve seen how to use selections and selectionArgs to filter the results of a query, let’s see where else this can be useful.

Say you want to use the query function to select tasks based on their priority. The priority is an integer level 1, 2, or 3. 1 is the highest priority and 3 is the lowest.

Based on what you know about the selection and selectionArgs parameters of your query() method, which of these method calls do you think will select only the highest priority rows of data? (Remember priority = 1 is the highest priority level)

SOLUTION: getContentResolver().query(TaskContentProvider.CONTENT_URI, null, TaskContract.ItemEntry.COLUMN_PRIORITY + " = ?" , 1 , null);